package algorithm.leetcode.I1to100;

public class Q50 {
    public double myPow(double x, int n) {
        return n >= 0 ? myPowHelper(x, n) : 1/myPowHelper(x, -n);
    }

    public double myPowHelper(double x, int n) {
        if (n == 0) return 1.0;

        double y = myPowHelper(x, n/2);
        return (n&1)==1 ? y*y*x : y*y;
    }
}
